package com.jxmcloud.business.cut.aspect;

import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;

/**
 * @author chr
 * date 2022/2/10
 */
@Configuration
public class LogAdvisor extends AbstractPointcutAdvisor {

    /**
     * 方法增强
     */
    private final Advice advice;
    /**
     * 切点
     */
    private final Pointcut pointcut;

    public LogAdvisor(LogInterceptor logInterceptor) {
        this.advice = logInterceptor;
//        this.pointcut = AnnotationMatchingPointcut.forMethodAnnotation(CutLog.class);
        // 创建AspectJ表达式切点
        AspectJExpressionPointcut expressionPointcut = new AspectJExpressionPointcut();
        // 设置扫描的包路径（示例：扫描com.jxmcloud.business.cut.service包下所有方法）
        expressionPointcut.setExpression(
                "execution(* com.jxmcloud.business.cut.controller..*.*(..))"
        );
        this.pointcut = expressionPointcut;
        super.setOrder(1);
    }

    @Override
    @NonNull
    public Pointcut getPointcut() {
        return pointcut;
    }

    @Override
    @NonNull
    public Advice getAdvice() {
        return advice;
    }
}
